package com.example.basicquestions.questions.猜字谜;

import java.util.*;

/**
 * @author liw
 * @date 2023-03-09
 */
public class Testa {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] mimian = scanner.nextLine().split(",");
        String[] midi = scanner.nextLine().split(",");
        List<String> result = new ArrayList<String>();
        boolean found = false;
        for(int i = 0; i < mimian.length; i++) {
            for(int j = 0; j < midi.length; j++) {
                if(quchong(mimian[i],midi[j])){
                    result.add(midi[j]);
                    found = true;
                }
                if(paixu(mimian[i],midi[j])){
                    result.add(midi[j]);
                    found = true;
                }
            }
        }
        if(!found){
            result.add("not found");
        }
        String res = "";
        for(int i = 0; i < result.size(); i++){
            res = res + result.get(i)+",";
        }
        System.out.println(res);
    }

    public static boolean quchong(String mimian, String midi){
        char[] mmt = mimian.toCharArray();
        char[] mdt = midi.toCharArray();
        List<Character> mm = new ArrayList<>();
        mm.add(mmt[0]);
        for(int i = 1; i < mmt.length; i++){
            if(mmt[i] != mmt[i - 1]){
                mm.add(mmt[i]);
            }
        }
        List<Character> md = new ArrayList<>();
        md.add(mdt[0]);
        for(int i = 1; i < mdt.length; i++){
            if(mdt[i] != mdt[i - 1]){
                md.add(mdt[i]);
            }
        }

        if(mm.equals(md)){
            return true;
        }

        return false;
    }

    public static boolean paixu(String mimian, String mide){
        char[] mm = mimian.toCharArray();
        char[] md = mide.toCharArray();
        Arrays.sort(mm);
        Arrays.sort(md);
        if(mm.equals(md)){
            return true;
        }
        return false;
    }
}
